package pl.prv.polanie.client.panels.lists;

import pl.prv.polanie.client.dialogs.CreatePreferenceTypeDialog;
import pl.prv.polanie.client.dto.CSPreferenceTypeDTO;
import pl.prv.polanie.client.dto.CSVPreferenceTypeDTO;
import pl.prv.polanie.client.model.Cache;
import pl.prv.polanie.client.model.ViewDataProvider;
import pl.prv.polanie.client.widgets.table.TablePreferenceTypes;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Widget;

public class PreferenceTypesList extends ObjectsList {

	TablePreferenceTypes tablePreferenceTypes= new TablePreferenceTypes(this);
	
	public PreferenceTypesList() {
		
		CSPreferenceTypeDTO[] pts = Cache.getAllPreferenceTypes();
		
		add(tablePreferenceTypes);
		
		
		for (int i = 0; i < pts.length; i++) {
			
			CSPreferenceTypeDTO cs = pts[i];
			CSVPreferenceTypeDTO csv = ViewDataProvider.getCSVPreferenceType(cs);
			
			tablePreferenceTypes.addRow(cs, csv);
		}
		
		
		addRecordButton.addClickListener(new ClickListener(){
			public void onClick(Widget sender) {
				CreatePreferenceTypeDialog catd = new CreatePreferenceTypeDialog(PreferenceTypesList.this, null); 
				catd.center();
			}
		});
		
		removeSelectedRecordButton.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {
				tablePreferenceTypes.removeSelectedPreferenceTypeFromTable();
				removeSelectedRecordButton.setEnabled(false);
			}
		});
		
		setupButtons();
		
	}

	
	public void addCSPreferenceType(CSPreferenceTypeDTO csPreferenceType) {
//		CSVLecturerDTO csv = ViewDataProvider.getCSVLecturer(csLecturer);
		
		tablePreferenceTypes.saveOrUpdatePreferenceTypeInTable(csPreferenceType);
//		tablePreferenceTypes.addRow(csLecturer, csv);
	}
	
	public void removeSelectdCSLecturer() {
		tablePreferenceTypes.removeSelectedPreferenceTypeFromTable();
	}
	
	
}
